package cn.seapon.talker.common;

import org.json.JSONException;
import org.json.JSONObject;

/** 
 * @author 作者 E-mail: 
 * @version 创建时间：2015年1月3日 下午10:19:06 
 * 类说明 
 */
public class LoginRequestEntity {
	//登录账户名
	private String account = "";
	//加密后的密码
	private String passwd = "";
	//验证码
	private String captcha = "";
	//账户类型,默认为ID类型
	private int type = 1;
	
	private JSONObject jsonObject;
	
	public JSONObject getJSONObject() {
		jsonObject = new JSONObject();
		try {
			jsonObject.put("account", account);
			jsonObject.put("passwd", passwd);
			jsonObject.put("captcha", captcha);
			jsonObject.put("type", type);
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
		return jsonObject;
	}
	
	public static LoginRequestEntity getObjectFromJson(JSONObject jsonObject){
		LoginRequestEntity entity = new LoginRequestEntity();
		try {
			String account = jsonObject.getString("account");
			String passwd = jsonObject.getString("passwd");
			String captcha = jsonObject.getString("captcha");
			int type  = jsonObject.getInt("type");
			entity.setType(type);
			entity.setAccount(account);
			entity.setCaptcha(captcha);
			entity.setPasswd(passwd);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return entity;
	}
	
    /**
     * 获得JSON字符串
     * @return
     */
    public String getJSONString(){
    	JSONObject obj = getJSONObject();
    	return obj.toString();
    }
	
	/**
	 * 账户类型：手机用户，邮箱用户，标示符类型
	 * @author Asuron
	 * Created on 2015年1月3日 下午10:20:34
	 */
	public static class  AccountType{
		public static final int PHONE_TYPE = 1;
		public static final int EMAIL_TYPE = 1;
		public static final int ID_TYPE = 1;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPasswd() {
		return passwd;
	}

	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}

	public String getCaptcha() {
		return captcha;
	}

	public void setCaptcha(String captcha) {
		this.captcha = captcha;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public LoginRequestEntity() {
	}

}
